/*
 * 
 * Created on Jul 30, 2005
 */
package com.wgo.precise.client.ui.view.util;

import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

import com.wgo.precise.client.ui.controller.Registry;
import com.wgo.precise.client.ui.model.facade.IModelPersistable;


public class ModelPersistable implements IPersistableElement {

    private IModelPersistable item;

    public ModelPersistable(IModelPersistable item) {
        this.item = item;
    }

    /**
     * @see org.eclipse.ui.IPersistableElement#getFactoryId()
     */
    public String getFactoryId() {
        return Registry.ELEMENT_FACTORY_ID;
    }

    public IModelPersistable getItem() {
        return this.item;
    }
    
    /**
     * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
     */
    public void saveState(IMemento memento) {
        Long identifier = null;
        String title = "Unknown title";
        String description = "Unknown description.";
        if (item != null ) {
            identifier = item.getIdentifier();
            title = item.getText();
            description = item.getToolTipText();
        }
        long id = -999;
        if (null != identifier) {
        	id = identifier.longValue();
        }
        memento.putFloat(Registry.MEMENTO_IDENTIFIER_ID, id );
        memento.putString(Registry.MEMENTO_TITLE_ID, title);
        memento.putString(Registry.MEMENTO_DESCRIPTION_ID, description);
        memento.putString(Registry.MEMENTO_CLASS_NAME_ID, item.getDomainObjectType().getName());
    }
    
}